package com.api.gbhg.daizhishun.service;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.daizhishun.Vo.InDetailExpenseAccountVo;
import com.api.gbhg.daizhishun.Vo.NewDemandVo;
import com.api.gbhg.daizhishun.dao.AccountingRoleDaoImpl;
import com.api.gbhg.daizhishun.dao.ReimbursementDao;
import com.api.gbhg.daizhishun.util.GenerateBudgetJobOrder;
import weaver.conn.RecordSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: daizhishun
 * @date: 2021/4/20
 **/
@Path("/gb/reimbursementlist")
public class AccountingRoleServiceImpl implements AccountingRoleService {

    AccountingRoleDaoImpl accountingRoleDao = new AccountingRoleDaoImpl();
    GenerateBudgetJobOrder generateBudgetJobOrder = new GenerateBudgetJobOrder();


    @POST
    @Path("/selectallexpenseaccount")
    @Produces(MediaType.APPLICATION_JSON)
    public  String getlist(Map<String,Object> map) {
//        User user = HrmUserVarify.getUser(request, response);  //得到当前用户
//        int userId = user.getUID(); //得到当前用户id

        String jbrId = map.getOrDefault("jbrId","").toString();
        String dw = map.getOrDefault("dw","").toString();
        String startTime = map.getOrDefault("startTime","").toString();
        String endTime = map.getOrDefault("endTime","").toString();
        String agent = map.getOrDefault("agent","").toString();
        String year = map.getOrDefault("year","").toString();
        String requestId = map.getOrDefault("requestId","").toString();
        String startMoney = map.getOrDefault("startMoney","").toString();
        String endMoney = map.getOrDefault("endMoney","").toString();
        List<Map<String,Object>> list = new ArrayList<>();

        //待办
        RecordSet filter1 = ReimbursementDao.filter(agent, startTime, endTime,dw,year,requestId);
        while (filter1.next()){
            Map<String, Object> mapdate = ReimbursementDao.workflowinfo(filter1.getStringNoTrim("requestid")
                    ,filter1.getStringNoTrim("requestname"),startMoney,endMoney);
            if (!mapdate.isEmpty()){
                list.add(mapdate);
            }
        }
        return JSON.toJSONString(list);

    }


    @Override
    @POST
    @Path("/insertcashierrole")
    @Produces(MediaType.APPLICATION_JSON)
    public boolean SelectCashierRole(List requestid)  {
        boolean expenseAccountVos = true;
        try {
            if (requestid.size()!=0){
                expenseAccountVos = accountingRoleDao.SelectCashierRole(requestid);
            }else{
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return expenseAccountVos;
    }

    @Override
    @POST
    @Path("/selecttrainingreimbursementbylist")
    @Produces(MediaType.APPLICATION_JSON)
    public List<NewDemandVo> SelectTrainingReimbursementByList(Map map) {
        return accountingRoleDao.SelectTrainingReimbursementByList(map);
    }

    @Override
    @POST
    @Path("/selectparticularreport")
    @Produces(MediaType.APPLICATION_JSON)
    public List<InDetailExpenseAccountVo> SelectTrainingReimbursementByA(Map map) {
        return accountingRoleDao.SelectTrainingReimbursementByA(map);
    }

    @Override
    @POST
    @Path("/updateexpenseaccountzfl")
    @Produces(MediaType.APPLICATION_JSON)
    public boolean updateExpenseAccountZfl(List<Map> list) {
        return accountingRoleDao.updateExpenseAccountZfl(list);
    }

}
